# Built-In Example AI

# Title: fangnifengzheng
# Author: team-5
# Version: 1.0.0
# Date: 11/12/2020

import game.tcturtle


class CombatTurtle(game.tcturtle.TurtleParent):

    def class_name():
        return "ct_fangnifengzheng"

    # -------------------------------------------------------------------------

    def class_desc():
        return "风筝无风险，锤爆不可能"

    # -------------------------------------------------------------------------

    def class_shape():

        return 4

    # =========================================================================

    def setup(self):
        """CombatTurtle.setup() -> None
        Initialization code for Combat Turtle.
        """
        self.flag = self.x < self.other_x

    # -------------------------------------------------------------------------

    def step(self):
        if self.line_of_sight():
            if self.health > self.other_health:
                self.turn_towards()
                self.forward()
                if (self.can_shoot
                        and abs(self.relative_heading_towards()) <= 5
                        and self.line_of_sight()
                        and self.distance() <= self.missile_range):
                    self.shoot()
            else:
                self.turn_towards()

                if self.flag:
                    if self.distance() > 3.9 * self.missile_radius:
                        self.forward()
                    else:
                        self.backward()
                else:
                    if self.distance() > 4 * self.missile_radius:
                        self.forward()
                    else:
                        self.backward()
                if (self.can_shoot
                        and abs(self.relative_heading_towards()) <= 5
                        and self.line_of_sight()):
                    self.shoot()
        else:
            self.left(0.1)
            self.forward()
